<template>
  <f7-page
    :name="name"
    @page:init="pageInit"
    @page:beforeremove="pageBeforeRemove"
    @page:afterin="onPageAfterIn"
    @page:beforeout="onPageBeforeOut"
    infinite
    :infinite-distance="50"
    :infinite-preloader="preloader"
    @infinite="getNextlawList"
  >
    <div class="fab fab-right-bottom" @click="tipPersonPage">
      <a>
        <i class="icon f7-icons">person</i>
      </a>
    </div>
    <list-null :len="listArr.length" warn-info="暂无数据"></list-null>
    <div class="list">
      <ul>
        <li v-for="el in listArr" :key="el.id+'-li'" @click="tipDetailPage(el)">
          <a href="#" class="item-link item-content">
            <div class="item-media">
              <img class="item-media-img" :src="el.thumb ? el.thumb : portraitLogo" alt="徽章" />
            </div>
            <!-- <div
              class="item-media-img-div"
              v-if="el.thumb"
              :style="{'background-image': 'url('+el.thumb+')'}"
            ></div>-->
            <div class="item-inner">
              <div class="item-title">
                <div class="item-header"></div>
                {{el.title}}
                <div class="item-footer">{{el.create_time ? el.create_time.substring(0,10) : ''}}</div>
              </div>
              <div class="item-after">
                <span v-if="el.type == 'cancel'">已取消</span>
                <span v-if="el.type == 'checking'">已报名</span>
                <span v-if="el.type == 'success'">已录取</span>
              </div>
            </div>
          </a>
        </li>
      </ul>
    </div>
  </f7-page>
</template>

<script>
import Storage from "../../mod/storage";
import StringUtils from "../../js/mod.string";
import ListNull from "../components/null-list.vue";
import Log from "../../mod/log.js";
import strings from "../../assets/strings";
import cordova from "../../js/cordova-app";
import Utils from "../../js/mod.utils";
import String from "../../js/mod.string";
import Http from "../../js/mod.http";
import ConstantUtils from "../../js/vue.constant";

const name = strings.page.law.list;
const log = new Log(name);

export default {
  components: {
    ListNull,
  },
  data() {
    return {
      preloader: true,
      loading: true,
      curPage: 1,
      totalPage: 0,
      pageSize: 10,
      listArr: [],
      portraitLogo: "./static/images/logo.png",
      name: name,
    };
  },
  methods: {
    pageInit(event, pageData) {
      let _this = this;
      let pageSizeNum = Utils.setCurrentPageSize(_this, 48);
      _this.pageSize = pageSizeNum;
      if (pageSizeNum) {
        _this.getDataList(_this.curPage);
      }
    },
    pageBeforeRemove(event, pageData) {
      let _this = this;
    },
    onPageAfterIn() {
      let _this = this;
      Utils.setTitle(_this, "课程管理系统");
      Utils.setBack(_this, function (e) {
        //_this.onBack();
        Utils.close_window(_this); // 关闭页面
      });
      // cordova.addAndroidHook(_this);
    },
    onPageBeforeOut() {
      let _this = this;
      // cordova.removeAndroidHook(_this);
    },
    onUpdateLawList(_data) {
      let _this = this;
      _this.getDataList(1);
    },
    // 个人中心
    tipPersonPage: function () {
      let _this = this;
      Utils.load(_this, "/person-index/", {}, {});
    },
    getNextlawList() {
      let _this = this;
      if (!_this.loading) {
        return;
      }
      _this.loading = false;
      setTimeout(function () {
        if (_this.curPage >= _this.totalPage) {
          _this.preloader = false;
          return;
        }
        let curPageNumber = _this.curPage + 1;
        _this.getDataList(curPageNumber);
        _this.loading = true;
      }, 1000);
    },
    getDataList(curPage) {
      let _this = this;
      let _successList = function (res) {
        _this.totalPage = res.total ? res.total : 1;
        _this.curPage = res.page;
        let curResData = res.data ? res.data : [];

        if (_this.totalPage == 1) {
          _this.preloader = false;
        }

        if (_this.curPage <= 1) {
          _this.listArr = curResData;
        } else {
          let afterArr = _this.listArr;
          for (let i in curResData) {
            afterArr.push(curResData[i]);
          }
          _this.listArr = afterArr;
        }
      };
      let data = {
        openid: _this.$f7.data.openid,
        page: curPage,
        size: _this.pageSize,
      };
      let params = {
        url: Http.kInterfacePath.edu.list,
        data: data,
        warn_error: "获取第" + curPage + "页的列表失败！",
        success: _successList,
      };
      Http.ajax(_this, params);
    },
    tipDetailPage(item) {
      let _this = this;
      let data = {
        id: item.id,
      };
      Utils.load(_this, "/edu-detail/", data, {});
    },
    onBack() {
      let _this = this;
      _this.$f7router.back();
    },
    onResume() {
      log.w("onResume");
    },
    onPause() {
      log.w("onPause");
    },
  },
};
</script>

<style scoped>
</style>
